import javafx.util.Pair;

import java.util.HashMap;
import java.util.Map;


public class Solution20 {
    public static void main(String[] args) {
        Solution20 solution = new Solution20();
        int[] bills = {5,5,5,10,20};
        boolean b = solution.lemonadeChange(bills);
        System.out.println(b);
    }
    public boolean lemonadeChange(int[] bills) {
        int five =0;
        int ten =0;
        for(int bill:bills){
            if(bill == 5){
                five++;
            }else if(bill == 10){
                if(five>0){
                    five--;
                    ten++;
                }else{
                    return false;
                }
            }else{
                if(five>0 && ten>0){
                    five--;
                    ten--;
                    continue;
                }else if(five >2){
                    five -=3;
                }else{
                    return false;
                }
            }
        }
        return true;
    }

}
